%
% Author: Vasyl Mykhalchuk
% 
%
classdef MeshGraph < handle
    properties
        mMesh
        mAdjVertList
        mDistanceMatrix = 0;
        mNeighborMax
        mMinDist = 0;
    end % properties
    
    methods
        % Constructor
        function obj = MeshGraph(mesh, adjList)
            obj.mMesh = mesh;
            obj.mAdjVertList = adjList;
            [obj.mNeighborMax] = size(adjList, 2);                           
            obj.mDistanceMatrix = MeshGraph.getDistanceMatrix(mesh, adjList, obj.mNeighborMax);
        end % Constructor      
        
        function minDist = minDist(obj)
            numberV = obj.mMesh.mNumberV;
            for i = 1:numberV
                minDist(i, :) = obj.dijkstra(i);
            end % for
        end % function minDist
        
        function [v] = getVertForNeighborhood(obj, vertex, epsilon)
            if (obj.mMinDist == 0)
                minDist = obj.minDist();
                obj.mMinDist = minDist;
            end % if
            numberV = obj.mMesh.mNumberV;
            v = 0;
            k = 1;
            for i = 1:numberV;
                d = minDist(vertex, i);
                if (d < epsilon)
                    v(k) = i;
                    k = k + 1;
                end % if
            end % for
        end % function getVertForNeighborhood
        
    end % methods
    
    methods(Static)
        
      function dm = getDistanceMatrix(mesh, adjVertList, neighborMax)
          numberV = mesh.mNumberV;
          dm = zeros(numberV); 
          for vId = 1:numberV
              i = 1;
                while ( i < neighborMax )
                    v = adjVertList(vId, i);
                    if (v ~= 0)
                        dm(vId, v) = norm( mesh.getVertex(vId) - mesh.getVertex(v));
                    elseif ( v == 0)
                        i = neighborMax;
                    end % if
                    i = i + 1;
                end
            end % for
      end % function getDistanceMatrix
      
    end % Static methods
    
end % class

